package biznussoft.metercor.fragments;

import com.salesforce.androidsdk.app.SalesforceSDKManager;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import biznussoft.metercor.R;
import biznussoft.metercor.adapter.JobCheckListAdapter;
import biznussoft.metercor.listeners.GlobalListener;

public class JobCheckListFragment  extends Fragment{

	private ListView lv;
	private GlobalListener mHomeItemListener;

	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setHasOptionsMenu(true);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.jobsitechecklist_records, null);
	}
	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		mHomeItemListener = (GlobalListener) getActivity();
	}
	

	@Override
	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
		// TODO Auto-generated method stub
		super.onCreateOptionsMenu(menu, inflater);
		/*MenuItem addItem = menu.add("ERT Device Installation");                 
		MenuItemCompat.setShowAsAction(addItem,MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
		addItem.setIcon(R.drawable.add); */
		MenuItem addJobsite = menu.add("Jobsite Inspection Checklist");                 
		MenuItemCompat.setShowAsAction(addJobsite,MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
		addJobsite.setIcon(R.drawable.add);
		MenuItem actionItem = menu.add("Logout");                 
		MenuItemCompat.setShowAsAction(actionItem,MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
		actionItem.setIcon(R.drawable.logout); 
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub

		/*if(item.getTitle().equals("ERT Device Installation")){
			mHomeItemListener.getSignature("ERT");
		}
		 */
		if(item.getTitle().equals("Logout")){
			SalesforceSDKManager.getInstance().logout(getActivity());}
		if(item.getTitle().equals("Jobsite Inspection Checklist")){
			mHomeItemListener.getSignature("Jobsite");
		}
		return super.onOptionsItemSelected(item);

	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		lv = (ListView) getView().findViewById(R.id.listview);
	}

	public void showJobCheckList(){


		showRecords();

	}

	public void showRecords(){
		JobCheckListAdapter adapter = new JobCheckListAdapter(getActivity(),JobCheckListDumyFragment.list);
		lv.setAdapter(adapter);
	}



}